package md.lanjing.com.module_home.ui.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.lxh.baselibray.mvp.MvpActivity;
import com.lxh.baselibray.util.ObjectUtils;
import com.lxh.baselibray.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_home.R;
import md.lanjing.com.module_home.R2;
import md.lanjing.com.module_home.bean.NearDayProfitResponce;
import md.lanjing.com.module_home.bean.TodayProfitResponce;
import md.lanjing.com.module_home.contact.TodayProfitContact;
import md.lanjing.com.module_home.ui.adapter.TodayProfitAdapter;
import retrofit2.Response;

/**
 * 今日收益
 */
public class TodayProfitActivity extends MvpActivity<TodayProfitContact.TodayProfitPresent> implements TodayProfitContact.ITodayProfitView {
    @BindView(R2.id.tv_total_profit_value)
    TextView tvTotalProfitValue;
    @BindView(R2.id.tv_today_profit_value)
    TextView tvTodayProfitValue;
    @BindView(R2.id.rv_profit)
    RecyclerView rvProfit;
    @BindView(R2.id.tv_carton_take_value)
    TextView tvCartonTakeValue;
    @BindView(R2.id.tv_green_profit)
    TextView tvGreenProfit;




    List<NearDayProfitResponce.DataBean> mList;
    TodayProfitAdapter mAdapter;

    @Override
    public void initData(Bundle savedInstanceState) {

        mList = new ArrayList<>();
        mAdapter = new TodayProfitAdapter(R.layout.recy_item_today_profit, mList);
        LinearLayoutManager manager = new LinearLayoutManager(context);
        rvProfit.setLayoutManager(manager);
        rvProfit.setAdapter(mAdapter);

        mPresent.getTodayProfit(context);
        mPresent.getNearProfit(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_today_profit;
    }


    @Override
    protected TodayProfitContact.TodayProfitPresent createPresent() {
        return new TodayProfitContact.TodayProfitPresent();
    }

    @Override
    public void getTodayProfitData(Response<TodayProfitResponce> response) {
        if (response.body().getCode() == Constant.SUCCESS_CODE) {
            TodayProfitResponce.DataBean data = response.body().getData();
            if (ObjectUtils.isEmpty(response))return;
            tvTotalProfitValue.setText(data.getTotalIncomeCawd()+"");
            tvTodayProfitValue.setText(data.getTodayIncomeCawd()+"");
            tvGreenProfit.setText(data.getGreenCawd()+"");
            tvCartonTakeValue.setText(data.getAbsorbCawd()+"");
        } else {
            ToastUtils.showLongToast(context, response.body().getMsg());
        }
    }

    @Override
    public void getNearProfitData(Response<NearDayProfitResponce> response) {
        if (response.body().getCode() == Constant.SUCCESS_CODE) {
            List<NearDayProfitResponce.DataBean> data = response.body().getData();
            mList.addAll(data);
            mAdapter.notifyDataSetChanged();
        } else {
            ToastUtils.showLongToast(context, response.body().getMsg());
        }
    }

}
